package com.jd.tuning;

import com.jd.tuning.jvm.objectpool.datasource.CoolDataSource;
import com.jd.tuning.jvm.objectpool.datasource.DataSourceEndpoint;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.client.AsyncRestTemplate;

import javax.sql.DataSource;

@EnableAsync  //添加注解
@SpringBootApplication
@MapperScan("com.jd.tuning.mapper")
public class TuningApplication {

    public static void main(String[] args) {
        SpringApplication.run(TuningApplication.class, args);
    }


    /**
     * 数据源配置
     * @return
     */
    @Bean
    @Primary   //优先使用
    public DataSource coolDataSource(){
        return new CoolDataSource();
    }


    /**
     * 监控配置
     * @return
     */
    @Bean
    public DataSourceEndpoint dataSourceEndpoint(){
        return new DataSourceEndpoint((CoolDataSource) this.coolDataSource());
    }


    /**
     * 已经标记废弃，考虑到目前比较流行
     * @return
     */
    @Bean
    public AsyncRestTemplate asyncRestTemplate(){
        return new AsyncRestTemplate();
    }

}
